﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNAVE3D
{
    class ModeloAnimationparaplegico
    {
        Vector3 position;
        public Model[] model;
        public Matrix myWorld = Matrix.Identity; Texture2D tex;
        int frame = 0; float contador;    
        public ModeloAnimationparaplegico(Vector3 position, Model[] model, Texture2D tex)
        {
            this.tex = tex;
            myWorld.Translation = position; 
            this.position = position;
            this.model = model;
            myWorld *= Matrix.CreateScale(5);
        }
        //float divisor = 8.0f;
        float divisor = 0.005f;
        public void Update(GameTime gameTime)
        {
            myWorld.Translation = position;
            
            if (Keyboard.GetState().IsKeyDown(Keys.Up) && divisor > 0)
            {
                divisor -= 0.0005f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Down) && divisor < 0.01f)
            {
                divisor += 0.0005f;
            }

            contador += (float)gameTime.ElapsedGameTime.TotalMilliseconds * divisor;

            if (contador >= 1.0f)
            {
                contador = 0;
                if (frame == model.Length - 1)
                {
                    frame = 0;
                }
                else
                {
                    frame++;
                }   
            }
           

        }
        public void Draw(Matrix view, Matrix projection, GraphicsDevice g)
        {
            foreach (ModelMesh mesh in model[frame].Meshes)
            {
                foreach (BasicEffect effectI in mesh.Effects)
                {
                    effectI.EnableDefaultLighting();
                    effectI.Projection = projection;
                    effectI.View = view;
                    effectI.World = myWorld;
                    effectI.Texture = tex;
                    effectI.TextureEnabled = true;

                }
                mesh.Draw();
            }      
        }
    }
}
